#version 310 es
layout(local_size_x = 1, local_size_y = 1) in;
layout(binding = 0) readonly buffer Input0 {
    int data[];
} yData;
layout(binding = 1) readonly buffer Input1 {
    int data[];
} uData;

layout(binding = 2) readonly buffer Input3 {
    int data[];
} vData;

layout(binding = 3) writeonly buffer Output {
    int data[];
} rgbData;
void main()
{
    int idx = int(gl_GlobalInvocationID.x + gl_NumWorkGroups.x * gl_GlobalInvocationID.y);
    int width =  int(gl_NumWorkGroups.x);
    int height = int(gl_NumWorkGroups.y);
    int wx = idx - idx / height * width;
    int hy = idx / width;
    int uvId =  (hy /2) * (width/2) + (wx /2);


    float y = float(yData.data[idx]);
    float u = float(uData.data[uvId]);
    float v = float(vData.data[uvId]);
//
    rgbData.data[idx * 4 + 0] = int(y + (1.4075 * (v- 128.0)));
    rgbData.data[idx * 4 + 1] = int(y - 0.3455 *(u -128.0) - 0.7169 *(v -128.0));
    rgbData.data[idx * 4 + 2] = int(y + (1.779  * (u - 128.0)));
    rgbData.data[idx * 4 + 3] = 1;
}